package com.sinosoft.vaccinetoai.security.utils;

import com.sinosoft.vaccinetoai.security.model.CustomPrincipal;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

/**
 * Security工具类
 * @author xzh
 * @date 2022-10-24 16:45
 * @since 5.0.0
 */
public class SecurityUtils {

    /**
     * 获取当前Subject
     * @return {@link Subject }
     * @author xzh
     * @since 1.0.0
     */
    public static Subject getSubject() {
        return org.apache.shiro.SecurityUtils.getSubject();
    }

    /**
     * 获取当前Session
     * @return {@link Session }
     * @author xzh
     * @since 1.0.0
     */
    public static Session getSession() {
        return getSubject().getSession();
    }

    /**
     * 获取自定义认证对象
     * @return {@link CustomPrincipal }
     * @author xzh
     * @since 1.0.0
     */
    public static CustomPrincipal getPrincipal() {
        return (CustomPrincipal) getSubject().getPrincipal();
    }

}
